package com.abigdreamer.im.server.cmd.command;

import com.abigdreamer.im.server.cmd.commandAction.ActionFactory;
import com.abigdreamer.im.server.cmd.commandAction.CommandAction;
import com.abigdreamer.im.server.cmd.resouse.CMDConfig;
import com.abigdreamer.im.server.cmd.resouse.ConfigFactory;

/**
 */
public class Invoker {

	/**
	 * @param _commandStr
	 * @return
	 */
	public String execute(String _commandStr){
		//定义返回值
		String result = "";
		Command param=new Command(_commandStr);
		CMDConfig config=ConfigFactory.getInstance().getCMDConfig();
		//判断此命令是否合格
		boolean isRightCommand=config.contains(param);
		if(isRightCommand){
			ActionFactory factory=ActionFactory.getInstance();
			CommandAction action=factory.getCommandActionByID(param.getCommandName());
			result=action.handleMessage(param);
		}else{
			result="无法执行命令，请检查命令格式.请查看\"help\"命令";
		}
		return result;
	}
}
